package com.feicheng.house.service.impl;

import com.feicheng.house.entity.BuyOrderClientShopVo;
import com.feicheng.house.entity.ClientVipDepositVo;
import com.feicheng.house.entity.DepositRecordClientUserVo;
import com.feicheng.house.mapper.DepositRecordClientUserVoMapper;
import com.feicheng.house.result.ResultInfo;
import com.feicheng.house.service.IDepositRecordClientUserVoService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author feichengTech
 * @since 2021-11-10
 */
@Service
public class DepositRecordClientUserVoServiceImpl extends ServiceImpl<DepositRecordClientUserVoMapper, DepositRecordClientUserVo> implements IDepositRecordClientUserVoService {

	@Override
	public ResultInfo selectAll(Integer currentPage, Integer pageSize, String searchKey , String searchState ,String actionRange) {
		QueryWrapper<DepositRecordClientUserVo> recordWrapper = new QueryWrapper<DepositRecordClientUserVo>();
		if (StringUtils.hasLength(searchKey)) {
			recordWrapper.and(i -> i.like("client_name", searchKey)
						 .or().like("deposit_number", searchKey)
						 .or().like("account",searchKey));	
		}
		
		if (StringUtils.hasLength(searchState)) {
			recordWrapper.like("deposit_state", searchState);
						 
		}
		JSONArray actionArr = JSON.parseArray(actionRange);
		System.out.println(actionArr);
		if (!actionArr.isEmpty()) {						
			recordWrapper.between("time", actionArr.get(0), actionArr.get(1));		
			
		}
		
		// 创建分页查询			
		IPage<DepositRecordClientUserVo> pageInfo = new Page<DepositRecordClientUserVo>(currentPage, pageSize);
		return ResultInfo.success(this.page(pageInfo,recordWrapper));
	}

	@Override
	public ResultInfo getRecord(String depositNumber) {
		QueryWrapper<DepositRecordClientUserVo> queryWrapper = new QueryWrapper();
		queryWrapper.eq("deposit_number", depositNumber);
		
		return ResultInfo.success(this.getOne(queryWrapper));
	}


}
